package com.ljc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljc.common.BaseResponse;
import com.ljc.common.ResultUtils;
import com.ljc.model.dto.OrderAddRequest;
import com.ljc.model.dto.OrderQueryRequest;
import com.ljc.model.vo.OrderVO;
import com.ljc.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 下单
     */
    @PostMapping("/addOrder")
    public BaseResponse<OrderVO> addOrder(@RequestBody OrderAddRequest addOrderRequest, HttpServletRequest request) {
        OrderVO orderVO = orderService.addOrder(addOrderRequest, request);
        return ResultUtils.success(orderVO);
    }

    /**
     * 查看下单列表
     */
    @GetMapping("/list")
    public BaseResponse<Page<OrderVO>> listPageOrder(OrderQueryRequest orderQueryRequest, HttpServletRequest request) {
        Page<OrderVO> orderPage = orderService.listPageOrder(orderQueryRequest, request);
        return ResultUtils.success(orderPage);
    }
}
